# -*- coding: utf-8 -*-
# @Time : 2021/2/2 14:21
# @Author : shx
# @Email : 925126486@qq.com
# @File : sj_page.py
# @Project : test
from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from selenium.webdriver.support.select import Select
class SjPage(BasePage):
    url_ = 'http://192.168.1.49/crm3/index.php?m=business'
    addsj_locator = (By.XPATH, '/html/body/div[5]/div[2]/div[1]/div/a')
    tbody_locator = (By.CSS_SELECTOR,'#form1 > table > tbody')
    sj_tbody_locator = (By.TAG_NAME, 'tbody')
    tr_locator = (By.TAG_NAME, 'tr')
    td_locator = (By.TAG_NAME, 'td')
    td_a_locator = (By.LINK_TEXT, '推进')
    tdd_a_locator = (By.LINK_TEXT, '编辑')
    chakan_locator = (By.LINK_TEXT, '查看')
    status_id_locator = (By.NAME,'status_id')
    nextstep_time_locator = (By.ID,'nextstep_time')
    frame_locator = (By.XPATH,'/html/body/div[9]/iframe')
    day_locator = (By.XPATH,'/html/body/div/div[3]/table/tbody/tr[4]/td[5]')
    sure_locator = (By.ID,'dpOkInput')
    nextstep_locator = (By.ID,'nextstep')
    tuijin_locator = (By.XPATH,'//*[@id="dialog-advance"]/form/table/'
                                   'tbody/tr[5]/td[2]/input[1]')
    dayin_locator = (By.XPATH, '/html/body/div[5]/div[2]/div[1]/div/div/button')
    daochu_locator = (By.LINK_TEXT,'导出商机')
    sj_thead_locator = (By.TAG_NAME,'thead')
    td_input_locator = (By.TAG_NAME,'input')
    th_locator = (By.TAG_NAME,'th')
    select_locator = (By.ID,'field')
    bao_locator = (By.ID,'condition')
    serch_locator = (By.ID,'search')
    dian_locator = (By.ID, 'dosearch')
    fanhui_locator = (By.XPATH,'//*[@id="form1"]/table/tfoot/tr/td/input[3]')
    stat_locator = (By.LINK_TEXT,'统计')  ###
    show_locator = (By.ID,'show_status')  ###
    sho_locator = (By.ID,'show_source')  ###

    sjtj_locator = (By.XPATH,"/html/body/div[5]/div[1]/ul/li[2]/a")
    department_select_locator = (By.ID,"department")
    role_select_locator = (By.ID,"role")
    tj_serch_locator = (By.XPATH,"/html/body/div[5]/div[2]/div[1]/ul/li/form/ul/li[4]/button")
    sjtjbb_locator = (By.ID,"show_report")
    xsldt_locator = (By.ID,"show_status")
    sjjet_locator = (By.ID,"show_money")
    qsfx_day_locator = (By.ID,"show_day")
    tjbb_count_locator = (By.XPATH,"/html/body/div[5]/div[2]/div[3]/div[1]/table/tfoot/tr/td[1]")
    xsldt_tool_locator = (By.CSS_SELECTOR,"//*[@id='highcharts-24']/svg/g[1]")
    xsldt_print_locator = (By.XPATH,"/html/body/div[5]/div[2]/div[3]/div[3]/div/div/div/div/div[1]")
    sjjet_tool_locator = (By.XPATH,"/html/body/div[5]/div[2]/div[3]/div[4]/div/div/svg/g[1]")
    text_qsfx_day_locator = (By.CSS_SELECTOR, "#show_day")

    def add_sj(self):
        self.find_element(self.addsj_locator).click()

    def tbody_element(self):
        return self.find_element(self.tbody_locator)

    def enter_tj(self,col,sjname):
        """进入商机推进页面"""
        tbody_element = self.find_element(self.sj_tbody_locator)
        trs = tbody_element.find_elements(*self.tr_locator)
        for tr in trs:
            tds = tr.find_elements(*self.td_locator)
            if tds[col-1].text == sjname:
                tds[col+7].find_element(*self.td_a_locator).click()
                break

    def enter_bj(self,col,sjname):
        """进入商机编辑页面"""
        tbody_element = self.find_element(self.sj_tbody_locator)
        trs = tbody_element.find_elements(*self.tr_locator)
        for tr in trs:
            tds = tr.find_elements(*self.td_locator)
            if tds[col-1].text == sjname:
                tds[col+7].find_element(*self.tdd_a_locator).click()
                break

    def enter_ck(self,col,sjname):
        """进入商机编辑页面"""
        tbody_element = self.find_element(self.sj_tbody_locator)
        trs = tbody_element.find_elements(*self.tr_locator)
        for tr in trs:
            tds = tr.find_elements(*self.td_locator)
            if tds[col-1].text == sjname:
                tds[col+7].find_element(*self.chakan_locator).click()
                break

    def status(self,status_name):
        """选择状态"""
        hetong = self.find_element(self.status_id_locator)
        ht = Select(hetong)
        ht.select_by_visible_text(status_name)

    def nextstep_time(self):
        """弹出日期选择框"""
        self.find_element(self.nextstep_time_locator).click()

    def select_day(self):
        """选择日期"""
        self.driver.switch_to.frame(self.find_element(self.frame_locator))
        self.find_element(self.day_locator).click()

    def sure_element(self):
        """点击确定"""
        self.find_element(self.sure_locator).click()

    def nextstep(self,content):
        """输入下次联系内容"""
        self.find_element(self.nextstep_locator).send_keys(content)

    def advance(self):
        """点击推进"""
        self.find_element(self.tuijin_locator).click()

    def select_allsj(self):
        """全选商机"""
        thead_element = self.find_element(self.sj_thead_locator)
        trs = thead_element.find_element(*self.tr_locator)
        tds = trs.find_elements(*self.th_locator)
        tds[0].find_element(*self.td_input_locator).click()

    def dayin(self):
        """点击打印"""
        self.find_element(self.dayin_locator).click()

    def daochu(self):
        """点击导出"""
        self.find_element(self.daochu_locator).click()

    def alert_accept(self):
        """点击确定"""
        self.driver.switch_to.alert.accept()

    def search_tj(self,search_name):
        """选择搜索条件"""
        sele = self.find_element(self.select_locator)
        select = Select(sele)
        select.select_by_visible_text(search_name)

    def search_gx(self,search_gx):
        """选择搜索关系"""
        baohan = self.find_element(self.bao_locator)
        se_bao = Select(baohan)
        se_bao.select_by_visible_text(search_gx)

    def input_ss(self,content):
        """输入框模糊输入"""
        self.find_element(self.serch_locator).send_keys(content)

    def point_ss(self):
        """点击搜索"""
        self.find_element(self.dian_locator).click()

    def point_fh(self):
        """点击返回"""
        self.find_element(self.fanhui_locator).click()

    def get_current_url(self):
        return self.driver.current_url

    def point_statistical(self):
        """点击统计"""
        self.find_element(self.stat_locator).click()

    def show_loudou(self):
        """查看漏斗图"""
        self.find_element(self.show_locator).click()

    def show_source(self):
        """查看来源图"""
        self.find_element(self.sho_locator).click()

    def click_sjtj(self):
        self.find_element(self.sjtj_locator).click()

    def department_select(self):
        return Select(self.find_element(self.department_select_locator))

    def role_select(self):
        return Select(self.find_element(self.role_select_locator))

    def click_tj_serch(self):
        self.find_element(self.tj_serch_locator).click()

    def click_sjtjbb(self):
        self.find_element(self.sjtjbb_locator).click()

    def click_xsldt(self):
        self.find_element(self.xsldt_locator).click()

    def click_sjjet(self):
        self.find_element(self.sjjet_locator).click()

    def dy_tjbb_count(self):
        return self.find_element(self.tjbb_count_locator).text

    def click_xsldt_tool(self):
        self.find_element(self.xsldt_tool_locator).click()

    def xsldt_print_text(self):
        return self.find_element(self.xsldt_print_locator).text

    def qsfx_day(self):
        self.find_element(self.qsfx_day_locator).click()

    def text_qsfx(self):
        return self.find_element(self.text_qsfx_day_locator).text

    def text_sjjet(self):
        return self.find_element(self.sjjet_locator).text

    def text_xsldt(self):
        return self.find_element(self.xsldt_locator).text


